2.5.9.1 State variable
The State variables store the value permanently in the contract
storage. They can be accessed from anywhere in the Contract.
Refer to the following code:
// SPDX-License-Identifier: Some Identifier
pragma solidity ^0.8.10;
contract GetterSetterContract {
string value = “Some Value”;
function getValue() public view returns(string memory) {
return value;
}
function setValue(string memory newValue) public {
value = newValue;
}
}
2.5.9.2 Local Variable
A local variable can be accessed only within the context of a
function, and it cannot be accessed outside. Usually, these variables
are used to hold temporary values. Their main purpose is to help
with processing or calculating something and returning the final
value in the function’s response. Refer to the following code:
// SPDX-License-Identifier: Some Identifier
pragma solidity ^0.8.10;
contract SumContract {
function sum() public pure returns(uint) {
uint var1 = 10;
uint var2 = 20;
return var1 + var2;
}
}